package com.example.malltest.order.controller;


import com.example.malltest.common.R;
import com.example.malltest.order.entity.Order;
import com.example.malltest.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    /**
     * 结算购物车
     * @param order
     * @return
     */
    @PostMapping("add")
    public R<Void> add(@RequestBody @Validated Order order){
        orderService.add(order);
        return R.ok();
    }

    /**
     * 批量结算购物车
     * @param orders
     * @return
     */
    @PostMapping("add1")
    public R<Void> batchAdd(@RequestBody @Validated List<Order> orders) {
        orderService.batchAdd(orders);
        return R.ok();
    }

    /**
     * 获取订单列表
     * @return
     */
    @GetMapping("list")
    public R<List<Order>> getList(){
        List<Order> orders = orderService.getList();
        return R.ok(orders);
    }

    /**
     * 改变状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("status/{id}")
    public R<Void> status(@PathVariable Integer id,@RequestParam String status){
        orderService.status(id,status);
        return R.ok();
    }

    /**
     * 订单评价
     * @param id
     * @param commit
     * @return
     */
    @PostMapping("commit/{id}")
    public R<Void> commit(@PathVariable Integer id,@RequestParam String commit){
        orderService.commit(id,commit);
        return R.ok();
    }

    /**
     * 获取评价
     * @param id
     * @return
     */
    @GetMapping("getCommit/{id}")
    public R<String> getCommit(@PathVariable Integer id){
        String commit = orderService.getCommit(id);
        return R.ok(commit);
    }
}
